/*
 * @Title: 我的票选优品
 * @Author: xubing
 * @Date:   2018-12-19
 * @Last Modified by:   徐兵
 * @Last Modified time: 2018-12-19
 */
var dataInfo = {},
    template = {
        init: function () {
            dataInfo.init = new Vue({
                el: '#app',
                data: {
                    tabData: [{
                        name: '全部',
                    }, {
                        name: '正在进行',
                    }, {
                        name: '已结束',
                    }],
                    listData: [],
                    listLength: 1,
                    active: 0,
                    loading: false,
                    isLoading: false,
                    finished: false,
                    page: 1,
                    showNum: 0
                },
                methods: {
                    onLoad: function () {
                        this.getList()
                        this.loading = false;
                        if (this.listData.length >= dataInfo.init.listLength) {
                            this.finished = true;
                        }
                    },
                    onRefresh: function () { //下拉刷新
                        this.page = 1;
                        this.listData = [];
                        dataInfo.init.getList();
                        setTimeout(function () {
                            dataInfo.init.loading = false;
                            dataInfo.init.finished = false;
                            dataInfo.init.isLoading = false;
                        }, 500);
                    },
                    getList: function () {
                        ajaxTemplate(addressTest + SERVICE.FXPTqueryItems, function (data) {

                            if (data.tag == 0) {

                                dataInfo.init.listLength = data.data.total;
                                dataInfo.init.listData = dataInfo.init.listData.concat(data.data.result);
                                dataInfo.init.showNum = dataInfo.init.listData.length;

                            } else {
                                dataInfo.init.$toast(data.errMsg);
                                if (data.errMsg == '请求参数[access_token]不能为空！') {
                                    jumpLogin();
                                };
                            };
                        }, {
                            userId: userId,
                            activityStatus: !this.active ? '' : this.active,
                            page: this.page++,
                            limit: 5
                        });
                    },
                },
                watch: {
                    active: function (e) {
                        dataInfo.init.finished = false;
                        this.page = 1;
                        this.showNum = 1;
                        this.listData = [];
                        document.body.scrollTop = 0;
                        document.documentElement.scrollTop = 0;
                        dataInfo.init.getList();
                    }
                }
            });
            //初始化函数
        },
    };
template.init();